package fr.inserm.u674.chcdbweb.model.forms;

import java.util.ArrayList;
import java.util.List;

import fr.inserm.u674.chcdbweb.model.DAO.DAOException;
import fr.inserm.u674.chcdbweb.model.DAO.TissueDAO;
import fr.inserm.u674.chcdbweb.model.DAO.TissueExtractionDAO;
import fr.inserm.u674.chcdbweb.model.DTO.TissueExtraction;

public class ExtractionListForm extends Form {

	// Constants ----------------------------------------------------------------------------------



	private static final String FIELD_RESULT = "result";

	// Variables ----------------------------------------------------------------------------------

	private TissueExtractionDAO tissueExtractionDAO;

	// Constructors -------------------------------------------------------------------------------

	public ExtractionListForm(TissueDAO tissueDAO, TissueExtractionDAO tissueExtractionDAO) {
		this.tissueExtractionDAO = tissueExtractionDAO;
	}

	// Actions ------------------------------------------------------------------------------------

	public List<TissueExtraction> listExtractions() {
		List<TissueExtraction> returnedExtractions = new ArrayList<TissueExtraction>();
		try {
			returnedExtractions = tissueExtractionDAO.list(null);
		}
		catch (DAOException e) {
			setError(FIELD_RESULT, "Extraction list retrieval failed due to a database error. "
				+ "Please try again later. Detailed message : " + e.getMessage());
		}

		return returnedExtractions;
	}

	// Form Processors

}
